<?php
class AccountPartnerLoginAction extends BaseAction
{
    protected $http_method = 'get';
    public function __construct($uri)
    {
        parent::__construct($uri);
    }

    protected function logic()
    {
        $tmp = explode('/', $this->uri);
        $partner_name = $tmp[2];
        $target = '/';
        if(isset($_SERVER['HTTP_REFERER']) && ($_SERVER['HTTP_REFERER'] != 'http://www.doubanxia.com/accounts/login')) {
            $target = $_SERVER['HTTP_REFERER'];
        }
        setcookie('as', $target, time() + 86400, '/accounts'); //不要把cookie都种在根域名。所以这里种在本域名。
        $partner_app_conf = ConfLib::get($partner_name, 'app');
        $this->output['http']['status_code'] = 302;
        switch($partner_name) {
            case 'douban' :
                $this->output['http']['uri'] = 'https://www.douban.com/service/auth2/auth?client_id=' . $partner_app_conf['api_key'] . '&redirect_uri=' . urlencode($partner_app_conf['redirect_uri']) . '&response_type=code';
                break;
            case 'qq' :
                $this->output['http']['uri'] = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=' . $partner_app_conf['app_id'] . '&redirect_uri=' . urlencode($partner_app_conf['redirect_uri']);
                break;
            default :
                throw new Exception(); //todo
        }
        return true;
    }
}
?>
